var emoRange = "#comments p, div.emoWrap, div.post-body, #pra-comment",
    putEmoAbove = "#tombol-link",
    emoMessage = "tambahkan satu spasi sebelum menuliskan kode smiley ";

// Emoticon bar before comment-form
$(function() {
  $(putEmoAbove)
  .before('');
  var emo = function(emo,imgRep,emoKey) {
    $(emoRange)
     .each(function() {
      $(this)
	.html($(this)
	.html()
	.replace(/<br>:/g, "<br> :")
	.replace(/<br>;/g, "<br> ;")
	.replace(/<br>\?/g, "<br> ?")
	.replace(/<br>=/g, "<br> =")
	.replace(/<br>\^/g, "<br> ^")
	.replace(emo, "<img style='max-height:24px; border:none; background:none; cursor:pointer' src='"+imgRep+"' class='emo delayLoad' alt='"+emoKey+"' />"));
    });
  };
  emo(/:\!\!/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/110.gif", ":!!");
  emo(/:-c/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/101.gif", ":-c");
  emo(/:\)\]/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/100.gif", ":)]");
  emo(/\~X\(/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/102.gif", "~X(");
  emo(/:O\)/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/34.gif", ":O)");
  emo(/\&lt;:\-P/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/36.gif", "&lt;:-P");
  emo(/=P\~/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/38.gif", "=P~");
  emo(/\&lt;\):\)/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/48.gif", "&lt;):)");
  emo(/:ar\!/g, "http://l.yimg.com/a/i/us/msg/emoticons/pirate_2.gif", ":ar!");
  emo(/:o3/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/108.gif", ":o3");
  emo(/:@\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/49.gif", ":@)");
  emo(/3:-O/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/50.gif", "3:-O");
  emo(/:\(\|\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/51.gif", ":(|)");
  emo(/~:&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/52.gif", "~:&gt;");
  emo(/@\};-/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/53.gif", "@};-");
  emo(/%%-/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/54.gif", "%%-");
  emo(/\*\*==/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/55.gif", "**==");
  emo(/\(\~\~\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/56.gif", "(~~)");
  emo(/\~O\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/57.gif", "~O)");
  emo(/\*-:\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/58.gif", "*-:)");
  emo(/8-X/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/59.gif", "8-X");
  emo(/=:\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/60.gif", "=:)");
  emo(/&gt;-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/61.gif", "&gt;-)");
  emo(/\$-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/64.gif", "$-)");
  emo(/\[-X/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/68.gif", "[-X");
  emo(/\\:D\//ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/69.gif", "&#92;:D/");
  emo(/:-j/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/78.gif", ":-j");
  emo(/\(\*\)/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/79.gif", "(*)");
  emo(/o-\&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/72.gif", "o-&gt;");
  emo(/o=\&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/73.gif", "o=&gt;");
  emo(/o-\+/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/74.gif", "o-+");
  emo(/\(%\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/75.gif", "(%)");
  emo(/:bz/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/115.gif", ":bz");
  emo(/\[..\]/g, "http://l.yimg.com/a/i/us/msg/emoticons/transformer.gif", "[..]");
  emo(/&gt;:\//g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/70.gif", "&gt;:/");
  emo(/%\*-\{/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/down_on_luck.gif", "%*-{");
  emo(/\'\+\_\+/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/cold.gif", "&#39;+_+");
  emo(/o\|:-\)/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/catch.gif", "o&#124;:-)");
  emo(/\^:\)\^/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/77.gif", "^:)^");
  emo(/:-\@/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/76.gif", ":-@");
  emo(/:-L/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/62.gif", ":-L");
  emo(/o\|\\\~/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/sing.gif", "o&#124;&#92;~");
  emo(/\'\@-\@/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/search_me.gif", "&#39;@-@");
  emo(/o\|\^_\^\|o/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/music.gif", "o|^_^|o");
  emo(/:\(\game\)/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/play_game.gif", ":(game)");
  emo(/:\(tv\)/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/tv.gif", ":(tv)");
  emo(/%\|\|:-\{/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/unlucky.gif", "%||:-{");
  emo(/\'\@\^\@\|\|\|/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/dizzy.gif", "&#39;@^@|||");
  emo(/\\m\//ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/111.gif", "&#92;m/");
  emo(/:dead/ig, "http://www.sherv.net/cm/emoticons/war/shot-in-head-1.gif", ":dead");
  emo(/:bom2/ig, "http://www.sherv.net/cm/emoticons/war/bomb.gif", ":bom2");
  emo(/:bom1/ig, "http://www.sherv.net/cm/emoticons/war/exploding-bomb.gif", ":bom1");
  emo(/:shoot5/ig, "http://www.sherv.net/cm/emoticons/guns/tommy-submachine-gun.gif", ":shoot5");
  emo(/:shoot4/ig, "http://www.sherv.net/cm/emoticons/guns/double-barrel-shotgun.gif", ":shoot4");
  emo(/:shoot3/ig, "http://www.sherv.net/cm/emoticons/guns/shooting-two-guns.gif", ":shoot3");
  emo(/:shoot2/ig, "http://www.sherv.net/cm/emoticons/guns/shooting-guns.gif", ":shoot2");
  emo(/:shoot1/ig, "http://www.sherv.net/cm/emoticons/guns/big-machine-gun.gif", ":shoot1");
  emo(/:bolakbalik/ig, "https://garis.googlecode.com/svn/wiki/bolakbalik.gif", ":bolakbalik");
  emo(/:-SS/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/42.gif", ":-SS");
  emo(/:-\?\?/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/106.gif", ":-??");
  emo(/\~x\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/102.gif", "~x(");
  emo(/:-t/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/104.gif", ":-t");
  emo(/:-\h/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/103.gif", ":-h");
  emo(/\[-O\&lt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/63.gif", "[-O&lt;");
  emo(/:\)\&gt;-/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/67.gif", ":)&gt;-");
  emo(/;\)\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/71.gif", ";))");
  emo(/:-\&gt;\~\~/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/spooky.gif", ":-&gt;~~");
  emo(/\&gt;:P/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/47.gif", "&gt;:P");
  emo(/=D\&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/41.gif", "=D&gt;");
  emo(/\&amp;\[\]/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/gift.gif", "&amp;[]");
  emo(/:-\(\|\|&gt;/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/give_up.gif", ":-(||&gt;");
  emo(/\:\"\&gt;/gi, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/9.gif", ":&quot;&gt;");
  emo(/:\&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/15.gif", ":&gt;");
  emo(/\&gt;:\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/19.gif", "&gt;:)");
  emo(/8\-&gt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/105.gif", "8-&gt;");
  emo(/\&gt;:D\&lt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/6.gif", "&gt;:D&lt;");
  emo(/:::\^\^:::/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/hot.gif", ":::^^:::");
  emo(/\^O\^\|\|3/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/eat.gif", "^O^||3");
  emo(/:puke!/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/puke.gif", ":puke!");
  emo(/\(:\|/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/37.gif", "(:|");
  emo(/:\(\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/20.gif", ":((");
  emo(/\/:\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/23.gif", "/:)");
  emo(/:-\&amp;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/31.gif", ":-&amp;");
  emo(/:\(fight\)/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/fight.gif", ":(fight)");
  emo(/:\)\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/21.gif", ":))");
  emo(/;;\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/5.gif", ";;)");
  emo(/:\)/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/1.gif", ":)");
  emo(/:\(/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/2.gif", ":(");
  emo(/;\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/3.gif", ";)");
  emo(/:D/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/4.gif", ":D");
  emo(/:-\//ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/7.gif", ":-/");
  emo(/:x/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/8.gif", ":x");
  emo(/:p/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/10.gif", ":p");
  emo(/:-p/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/10.gif", ":-p");
  emo(/:-\*/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/11.gif", ":-*");
  emo(/=\(\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/12.gif", "=((");
  emo(/:O/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/13.gif", ":O");
  emo(/:-O/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/13.gif", ":-O");
  emo(/X\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/14.gif", "X(");
  emo(/X-\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/14.gif", "X(");
  emo(/B-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/16.gif", "B-)");
  emo(/\#:-S/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/18.gif", "#:-S");
  emo(/:-S/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/17.gif", ":-S");
  emo(/=\)\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/24.gif", "=))");
  emo(/O:-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/25.gif", "O:-)");
  emo(/\:\-bd/g, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/113.gif", ":-bd");
  emo(/:-B/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/26.gif", ":-B");
  emo(/=;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/27.gif", "=;");
  emo(/I-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/28.gif", "I-)");
  emo(/8-\|/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/29.gif", "8-|");
  emo(/\:-\$/gi, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/32.gif", ":-&#36;");
  emo(/\[-\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/33.gif", "[-(");
  emo(/8-\}/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/35.gif", "8-}");
  emo(/:-\?/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/39.gif", ":-?");
  emo(/#-o/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/40.gif", "#-o");
  emo(/@-\)/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/43.gif", "@-)");
  emo(/:\^o/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/44.gif", ":^o");
  emo(/:-w/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/45.gif", ":-w");
  emo(/:-\&lt;/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/46.gif", ":-&lt;");
  emo(/\:-\"/gi, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/65.gif", ":-&quot;");
  emo(/:\|/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/22.gif", ":|");
  emo(/b-\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/66.gif", "b-(");
  emo(/%-\(/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/107.gif", "%-(");
  emo(/X_X/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/109.gif", "X_X");
  emo(/\^\#\(\^/ig, "http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/114.gif", "^#(^");
  emo(/\?@_@\?/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/studying.gif", "?@_@?");
  emo(/:-\)\/\\:-\)/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/high_five.gif", ":-)/&#92;:-)");
  emo(/\[\]==\[\]/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/exercise.gif", "[]==[]");
  emo(/\[\]---/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/cook.gif", "[]---");
  emo(/\~\^o\^\~/ig, "http://l.yimg.com/a/lib/msg/img/aurora/emot/201105/cheer.gif", "~^o^~");
});

var searchFormConfig = {
    url: "http://heningkara.blogspot.com", // URL Blog
    numPost: 9999, // Jumlah maksimal temuan
    summaryPost: true, // 'true' jika ingin menampilkan deskripsi posting
    summaryLength: 60, // Jumlah karakter ringkasan posting
    resultTitle: "Hasil penelusuran untuk kata kunci", // Judul hasil pencarian
    noResult: "No result", // Deskripsi 'tak ditemukan'
    resultThumbnail: true, // 'true' untuk menampilkan thumbnail posting
    thumbSize: 50, // Ukuran & resolusi thumbnail
    fallbackThumb: "http://2.bp.blogspot.com/-5sosqbvgRi4/UW4zbrXesJI/AAAAAAAABPs/pTP4l9VamM4/s1600/4TNP04I0VDET.JPG" // Fallback thumbnail untuk posting tak bergambar
};

/**
 * Blogger Quick Search Result JSON
 * Author: Taufik Nurrohman
 * URL: https://plus.google.com/108949996304093815163/about
 * See: http://hompimpaalaihumgambreng.blogspot.com/2012/09/membangun-aplikasi-quick-search-dengan.html
 */

// Just a shortcut for document.getElementById();
function getId(id) {
	return document.getElementById(id);
}

var config = searchFormConfig,
	input = getId('feed-q-input'),
	resultContainer = getId('search-result-container'),
	resultLoader = getId('search-result-loader'),
	skeleton = '';

// The Most Basic :: JSON caller function to display the list of posts in the container
function showResult(json) {
	var entry = json.feed.entry ? json.feed.entry : "", url, summary, img;
	skeleton  = '<h4>' + config.resultTitle + ' &quot;' + input.value + '&quot;</h4>';
	skeleton += '<a title="Close" style="display:block;position:absolute;top:10px;right:12px;line-height:normal;text-decoration:none;color:inherit;font-size:150%;" href="#close" onclick="resultContainer.style.display=\'none\';return false;">&times;</a><ol>';
	if (entry === "") {
		skeleton += '<li>' + config.noResult + '</li>';
	}
	for (var i = 0; i < config.numPost; i++) {
		if (i == entry.length) break;
		var mark = new RegExp(input.value, "ig"), entries = entry[i], title = entries.title.$t.replace(mark, "<mark>"+input.value+"</mark>");
		for (var j = 0; j < entries.link.length; j++) {
			if (entries.link[j].rel == 'alternate') {
				url = entries.link[j].href;
				break;
			}
		}
		summary = ("summary" in entries && config.summaryPost === true) ? entries.summary.$t : "";
		if (config.resultThumbnail === true) {
			img = ("media$thumbnail" in entries) ? entries.media$thumbnail.url.replace(/\/s[0-9]+\-c/g, "/s"+config.thumbSize+"-c") : config.fallbackThumb;
		}
		summary = summary.replace(/<(.*?)>/g, "");
		if (summary.length > config.summaryLength) {
			summary = summary.substring(0, config.summaryLength) + '...';
		}
		summary = summary.replace(mark, "<mark>"+input.value+"</mark>");
		skeleton += '<li><img style="width:'+config.thumbSize+'px;height:'+config.thumbSize+'px;" src="'+img+'" alt="" /><a href="'+url+'" target="_blank">'+title+'</a>'+summary+'</li>';
	}
	skeleton += '</ol>';
	resultContainer.innerHTML = skeleton;
	resultLoader.style.display = "none";
	resultContainer.style.display = "block";
}

// Insert an empty <script> tag with ID of 'search-feed-script'
(function() {
	var s = document.createElement('script');
		s.type = "text/javascript";
		s.id = "search-feed-script";
	document.getElementsByTagName('head')[0].appendChild(s);
})();

// Used to manipulate the 'q' parameter value in the 'search-feed-script' based on keywords that written in the search input
function updateScript() {
	resultContainer.style.display = "none";
	resultLoader.style.display = "block";
	var script = getId('search-feed-script'),
		newScript = document.createElement('script');
	newScript.id = "search-feed-script";
	newScript.type = "text/javascript";
	newScript.src = config.url+"/feeds/posts/summary?alt=json-in-script&q="+input.value+"&max-results="+config.numPost+"&callback=showResult";
	// Remove the empty script that we crated before...
	script.parentNode.removeChild(script);
	// Then, insert a new script with the callback of showResult() fuunction based on the 'q' parameter value of input.value
	// So, the result will be like this => http://blog_name.blogspot.com/feeds/posts/summary?alt=json-in-script&q=QUERIES&max-results=XXXX&callback=showResult
	document.getElementsByTagName('head')[0].appendChild(newScript);
	return false;
}

// Used to hide the search result container when the search input value is empty
function resetField() {
	if (input.value === "") {
		resultContainer.style.display = "none";
		resultLoader.style.display = "none";
	}
}